package com.ry.day1129;

import java.util.HashSet;
import java.util.Set;

public class LC353 {

    static class Solution {
        /**
         * @param s: a string
         * @return: a string
         */
        public String largestLetter(String s) {
            Character ans = null;
            Set<Character> set = new HashSet<>();
            for (int i = 0; i <s.length() ; i++) {
                char key = s.charAt(i);
                if(key >='a' && key<='z'){
                    int diff = key-'a';
                    char daxie = (char)('A'+ diff);
                    if(set.contains(daxie)){
                        if(ans ==null){
                            ans = daxie;
                        }else{
                            if(daxie-ans >0) {
                                ans = daxie;
                            }
                        }
                    }
                }

                if(key >='A' && key<='Z'){
                    int diff = key-'A';
                    char xiaoxie = (char)('a'+ diff);
                    if(set.contains(xiaoxie)){
                        if(ans ==null){
                            ans = key;
                        }else if(key-ans >0){
                            ans =key;
                        }
                    }
                }

                set.add(key);
            }
            if(ans == null){
                return "NO";
            }else{
                return ans+"";
            }
        }
    }


    public static void main(String[] args) {
        Solution obj = new Solution();
        System.out.println(obj.largestLetter("admeDCAB"));
        System.out.println(obj.largestLetter("adme"));
    }
}
